﻿using System;
using System.Collections.Generic;
using System.Text;

using DotSpatial.Data;
using DotSpatial.Topology;

using System.Drawing.Drawing2D;

using System.Drawing;






namespace FXnaGis.Shapes
{

    /// <summary>
    /// 这里指的是特殊图形，带有旋转角的矩形，角度基于Y轴长
    /// </summary>
    [Serializable]
    public class FRectangleShape : FShape
    {

       


        

        /// <summary>
        /// 已知第一点、长、宽、角度求四个点
        /// </summary>
        /// <param name="FirstCoord"></param>
        /// <param name="XLength"></param>
        /// <param name="YLength"></param>
        /// <param name="Angle"></param>
        /// <param name="id"></param>
        public FRectangleShape(Coordinate FirstCoord, double XLength, double YLength, double Angle, string id)
            : base(id)
        {



            this._firstCoord =(Coordinate) FirstCoord.Clone();

          
           

            this._xLength = XLength;
            this._yLength = YLength;

            this._angle = Angle;

        
           

          


        }


        Coordinate _firstCoord;

        public Coordinate FirstCoord
        {
            get { return _firstCoord; }
            set { _firstCoord = value; }
        }


        double _xLength;

        public double XLength
        {
            get { return _xLength; }
            set { _xLength = value; }
        }

        double _yLength;

        public double YLength
        {
            get { return _yLength; }
            set { _yLength = value; }
        }

        double _angle;

        public double Angle
        {
            get { return _angle; }
            set { _angle = value; }
        }

        public override void Move(double xOffset, double yOffset, double zOffset)
        {
            this._firstCoord.X += xOffset;

            this._firstCoord.Y += yOffset;


        }

        public override void Draw(FMapArgs args)
        {
          

            PolyStyle pyStyle =this.Parent.PolyStyle;



            System.Drawing.Point pt=args.ProjToPixel(this._firstCoord);


            double xl = args.ProjToPixel(this._xLength);
            double yl = args.ProjToPixel(this._yLength);


            Rectangle rectange = new Rectangle(0,0,(int)xl,(int)yl);
            

            GraphicsPath path = new GraphicsPath();

            path.StartFigure();


            Matrix org=args.Device.Transform;

            Matrix shift = args.Device.Transform.Clone ();

            shift.Translate(pt.X,pt.Y);

            shift.Rotate((float)this._angle);

            path.AddRectangle(rectange);


            pyStyle.DrawPath(args.Device,path,1);
            pyStyle.FillPath(args.Device,path);


            args.Device.Transform = org;

            path.Dispose();

            


        }



        public override bool Intersects(DotSpatial.Topology.Envelope envelope)
        {
            return true;
        }



     
       


       



    }
}
